<template>
  <div class="container">
    <Nav />
    <div class="ad-h" v-if="flag" @click="adClick('path')">
      <span class="ad-h-close">
        广告
        <span @click="adhClose">x</span>
      </span>
    </div>
    <div class="ad-h-closed" v-if="!flag">CSDN已关闭此广告</div>
    <div class="row home-news">
      <div class="col-sm" style="padding-left:0;">
        <div class="home-news-header">
          <div class="home-news-title">
            <i class="home-news-icon"></i> 头条
          </div>
        </div>
        <div class="home-news-body">
          <img src="~@/assets/images/home/news1.jpg" alt />
          <div class="news-link">
            <a class="news-link-title" href>在软件工程领域，搞科研的这十年！</a>
            <a class="news-link-second" href>本文节选自《新程序员》004</a>
          </div>
        </div>
      </div>
      <div class="col-sm">
        <NewsBoard :records="records" :size="5" />
      </div>
      <div class="col-sm">
        <NewsBoard :records="hots" :size="5" :title="'热点'" />
      </div>
      <div class="col-sm" style="padding-right:0;">
        <Adv />
      </div>
    </div>
    <div class="home-row">
      <div class="home-col4">
        <NewsFlow />
      </div>
      <div class="home-col1">
        <StickyFlow />
      </div>
    </div>
  </div>
</template>

<script lang='ts'>
import { Component, Vue } from "nuxt-property-decorator";

@Component
export default class extends Vue {
  flag: boolean = true;

  created() {
    this.initHome();
  }
  initHome() {
    this.$store.commit("homeModule/initNavs");
    this.$store.commit("homeModule/initRecommends");
    this.$store.commit("homeModule/initLives");
    this.$store.commit("homeModule/initRecords");
    this.$store.commit("homeModule/initHots");
  }
  get records() {
    return this.$store.state.homeModule.records;
  }
  get hots() {
    return this.$store.state.homeModule.hots;
  }
  adhClose() {
    this.flag = false;
  }
  adClick(path: string) {
    this["$router"].push(path);
  }
}
</script>

<style lang='less' scoped>
.container {
  .wh(100%, auto);
  min-width: 1200px;
  .flex-box(column, flex-start);
  position: relative;
  padding-bottom: 20px;
  .ad-h {
    .wh(100%, 100px);
    margin-top: 95px;
    background: url("~@/assets/images/ad.png");
    background-size: cover;
    .ad-h-close {
      color: #fff;
      border: 1px solid #fff;
      border-radius: 2px;
      position: absolute;
      right: 20px;
      line-height: 18px;
      font-size: 12px;
      margin-top: 5px;
      padding-left: 5px;
      padding-right: 5px;
      span {
        cursor: pointer;
        z-index: 1;
      }
    }
  }
  .ad-h-closed {
    .wh(100%, 100px);
    margin-top: 95px;
    text-align: center;
    vertical-align: middle;
  }
  .home-news {
    .wh(100%, 355px);
    flex-wrap: nowrap;
    margin: 10px;
    .home-news-header {
      .home-news-title {
        .flex-box(row, flex-start);
        height: 26px;
        margin-bottom: 10px;
        font-size: 16px;
        font-weight: bolder;
      }
      .home-news-icon {
        .wh(24px);
        display: inline-block;
        background: url("~@/assets/images/home/news-icon.png");
        background-repeat: no-repeat;
        background-size: cover;
        margin-right: 5px;
      }
    }
    .home-news-body {
      width: 300px;
      img {
        width: 100%;
      }
      .news-link-title {
        width: 300px;
        margin-top: 5px;
        display: block;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;

        color: #000;
        font-size: 18px;
        font-weight: bold;
      }
      .news-link-second {
        width: 300px;
        margin-top: 5px;
        display: block;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;

        color: #999;
      }
    }
  }
  .home-row {
    .wh(100%, auto);
    .flex-box(row, flex-start, flex-start);
    margin-top: 30px;
    background-color: #fff;
    border-radius: 5px;
    .home-col4 {
      .wh(77%, auto);
      padding: 10px;
    }
    .home-col1 {
      .wh(23%, auto);
      min-width: 240px;
      padding: 10px;
    }
  }
}
</style>